﻿using BCGPSCommon;
using Microsoft.Extensions.Configuration;
using System.IO; 


namespace AppSocketControl
{
    public class ConfigurationManager
    {
        private static IConfigurationRoot config;
        public static IConfigurationRoot AppSettings { get { return config; } }
        public static string Get(string key)
        {
            return config[key];
        }
        static ConfigurationManager()
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json",optional: true, reloadOnChange: true);
            config = builder.Build();


            GeneralContainer.RedisNameSpaceAccountVehicle = AppSettings["Redis:RedisNameSpaceAccountVehicle"];
            GeneralContainer.RedisNameSpaceIMEIAlarm = AppSettings["Redis:RedisNameSpaceIMEIAlarm"];
            GeneralContainer.RedisNameSpaceIMEILocation = AppSettings["Redis:RedisNameSpaceIMEILocation"];
            GeneralContainer.RedisNameSpaceAccount = AppSettings["Redis:RedisNameSpaceAccount"];
            GeneralContainer.RedisNameSpaceIMEISendCmd = AppSettings["Redis:RedisNameSpaceIMEISendCmd"];
            GeneralContainer.RedisNameSpaceIMEIDevice = AppSettings["Redis:RedisNameSpaceIMEIDevice"];
            GeneralContainer.IsUseGpsDataValidCount = bool.Parse( AppSettings["Debug:IsUseGpsDataValidCount"]);
            GeneralContainer.Bat30LowPowerAlarmVoltage = float.Parse(AppSettings["BatLowPower:Bat30LowPowerAlarmVoltage"]);
            GeneralContainer.Bat42LowPowerAlarmVoltage = float.Parse(AppSettings["BatLowPower:Bat42LowPowerAlarmVoltage"]);
        }
    }
}
